package com.usian.behavior.service

import com.usian.behavior.mapper.ApFollowBehaviorMapper
import com.usian.common.BaseServiceImpl
import com.usian.model.behavior.dto.FollowBehaviorDto
import com.usian.model.behavior.pojos.ApFollowBehavior
import com.usian.model.common.dtos.ResponseResult
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service
import java.util.*

@Service
open class ApFollowBehaviorServiceImpl : BaseServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior>() {
    @Autowired
    lateinit var apBehaviorEntryServiceImpl: ApBehaviorEntryServiceImpl
    open fun saveFollowBehavior(dto: FollowBehaviorDto): ResponseResult<*> {
        val behaviorEntry = apBehaviorEntryServiceImpl.findByUserIdOrEquipmentId(dto.userId,0) ?: return errorResult
        return ResponseResult.okResult(save(ApFollowBehavior().apply {
            entryId = behaviorEntry.id
            createdTime = Date()
            articleId = dto.articleId
            followId = dto.followId
        }))
    }
}